<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        box-sizing: border-box;
        font-size: 16px;
      }
      .chat-container {
        width: 300px;
        height: 400px;
        overflow: hidden;
        /* max-height: 400px; */
        background: #1e1e2b;
        position: relative;
      }
      .chat-content {
        width: 280px;
        height: 400px;
        background: #2f2f40;
        overflow: hidden;
        z-index: 11;
        margin: 0 auto;
        padding: 10px;
        border-radius: 12px;
      }
      .q-img {
        width: 20px;
        height: 20px;
        border-radius: 50%;
        margin-bottom: 5px;
      }
      .a-img {
        width: 20px;
        height: 20px;
        border-radius: 50%;
        margin-bottom: 5px;
      }
      .chat-item {
        margin-bottom: 10px;
      }
      .content-msg {
        color: #fff;
        word-break: break-word;
      }
      .more-btn {
        height: 30px;
        line-height: 30px;
        position: absolute;
        bottom: 10px;
        left: 50%;
        transform: translateX(-50%);
        background: rgba(25, 34, 54, 0.8);
        color: #fff;
      }

      .read-more-btn {
        height: 35px;
        line-height: 35px;
        text-align: center;
        position: absolute;
        left: 50%;
        bottom: 10px;
        transform: translateX(-50%);
      }

      .read-more-btn div {
        background-color: #436bff;
        color: white;
        border: none;
        padding: 0 20px;
        border-radius: 20px;
        cursor: pointer;
        font-size: 14px;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
      }

      .read-more-btn button:hover {
        background-color: #365ace;
      }

      .message-source {
        font-size: 26px;
        line-height: 40px;
        word-wrap: break-word;
      }

      .message-source .source-title {
        font-weight: 600;
        margin: 16px 0 8px;
      }

      .message-source .source-item {
        margin-bottom: 8px;
        display: flex;
      }

      .message-source .source-item .item-value {
        color: #2a64f6;
        cursor: pointer;
      }
    </style>
  </head>
  <body>
    <div class="chat-container chat-box">
      <div class="chat-content">
        <!-- <div class="chat-item">
          <img
            src="../images/zx-question.png"
            class="avatar q-img"
            src=""
            alt=""
          />
          <div class="content-msg">11111</div>
        </div>
        <div class="chat-item">
          <img
            src="../images/zx-answer.png"
            class="avatar q-img"
            src=""
            alt=""
          />
          <div class="content-msg">
            222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
          </div>
        </div> -->

        <% messages.forEach(function(message) { %> <% if (message.direction=='Q'
        ) { %>
        <div class="chat-item">
          <img
            src="<%= base64Obj['zx-question.png']  %>"
            class="avatar q-img"
            src=""
            alt=""
          />
          <div class="content-msg"><%- marked(message.message) %></div>
        </div>
        <% } else { %>
        <div class="chat-item">
          <img
            src="<%= base64Obj['zx-answer.png']  %>"
            class="avatar a-img"
            src=""
            alt=""
          />
          <div class="content-msg">
            <!-- 放置markdown转换后的html -->
            <%- marked(message.message) %>
            <!-- 用户主动停止需要后面拼接  -->
            <% if (message.extField &&
            JSON.parse(message.extField).stopSend=='1' ) { %>
            <span
              style="
                font-size: 12px;
                display: inline-block;
                color: #c0c0c0;
                background: #f3f4f8;
                border-radius: 22px;
                line-height: 18px;
                padding: 0 8px;
                margin-left: 6px;
              "
              >用户已停止</span
            >
            <% } %>
          </div>
          <!-- 如果有参考来源显示 -->

          <% if (message && message.source && message.source.length) { %>
          <div class="message-source">
            <div class="source-title">参考来源：</div>

            <% message.source.forEach(function(item,index) { %>
            <div class="source-item">
              <div class="item-index"><%= index + 1 %>、</div>
              <div class="item-value van-multi-ellipsis--l3">
                <%= item.title %>
              </div>
            </div>
            <% }); %>
          </div>
          <% } %>
        </div>
        <% } %> <% }); %>
      </div>
      <div class="read-more-btn">
        <div>查看更多</div>
      </div>
    </div>

    <script>
      // function setRemUnit() {
      //   const baseWidth = 750; // 基准宽度
      //   const html = document.documentElement;
      //   const clientWidth = html.clientWidth;

      //   // 设置 html 元素的 font-size
      //   html.style.fontSize = `${(clientWidth / baseWidth) * 100}px`;
      // }

      // // 初次加载时设置
      // setRemUnit();

      // // 监听窗口尺寸变化
      // window.addEventListener("resize", setRemUnit);
    </script>
  </body>
</html>
